package com.gdc.cloud.controller;


import com.gdc.cloud.entities.CommonResult;
import com.gdc.cloud.entities.Payment;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * Description: 支付 Controller
 * @author: gdc
 * @date: 2022/5/23
 * @version 1.0
 */
@RestController
public class PaymentController {

    @Value("${server.port}")
    private String serverPort;

    /**
     * 此数据模拟从数据库查询
     */
    public static HashMap<Long, Payment> MAP = Maps.newHashMap();

    static {
        MAP.put(1L, new Payment(1L, "1111111111111111111111111"));
        MAP.put(2L, new Payment(2L, "2222222222222222222222222"));
        MAP.put(3L, new Payment(3L, "3333333333333333333333333"));
    }


    /**
     * 通过ID，获取数据
     *
     *  http://localhost:9004/payment/1
     *
     * @param id        ID
     * @return          数据
     */
    @GetMapping("payment/{id}")
    public CommonResult<Payment> getById(@PathVariable("id") Long id) {
        Payment payment = MAP.get(id);
        return new CommonResult<>(200, "from MySql, serverPort: " + serverPort, payment);
    }
}
